package com.ml.mall.utils;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

/**
 * Created by kyyang on 2021/3/26 16:32
 */
public class DataConversionUtils {


    public static void main(String[] args) {
        BigDecimal[] curDateMonthDataInit = getCurDateMonthDataInit("2021-01-01","2021-03-30", null);
        System.out.println(Arrays.toString(curDateMonthDataInit));
    }




    public static BigDecimal[]  getCurDateMonthDataInit(String startTime,String endTime, Map<String,Double> map){
        Calendar instance = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = new Date();
        try {
            parse = sdf.parse(startTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        instance.setTime(parse);
        int d = DateUtils.getDateDiff(startTime, endTime);
        BigDecimal[] bigDecimals = new BigDecimal[d];
        for(int i = 0;i<d;i++){
            BigDecimal hj = BigDecimal.ZERO;
            if(map!=null){
                String format = sdf.format(instance.getTime());
                Double aDouble = map.get(format);
                if(aDouble!=null){
                    hj = BigDecimal.valueOf(aDouble);
                }
            }
            bigDecimals[i] = hj;
            instance.add(Calendar.DAY_OF_MONTH,1);
        }
        return bigDecimals;
    }






}
